home *** CD-ROM | disk | FTP | other *** search
- Path: news.microsoft.com!news
- From: a-cnadc@microsoft.com (Dann Corbit)
- Newsgroups: comp.lang.c
- Subject: Re: Finding a prime number
- Date: 15 Feb 1996 00:28:47 GMT
- Organization: Microsoft Corporation
- Message-ID: <4ftunv$vc0@news.microsoft.com>
- References: <4e875s$nqk@reader2.ix.netcom.com> <7c8_9601301722@tor250.org> <4f7n1o$ol9@mother.usf.edu> <4fl2tl$ln6@ns2.emirates.net.ae> <4fnnfuINNib7@keats.ugrad.cs.ubc.ca> <4fp2kt$pks@oban.cc.ic.ac.uk>
- NNTP-Posting-Host: 157.57.171.202
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4fp2kt$pks@oban.cc.ic.ac.uk>, a.kruczkowski@ic.ac.uk says...
- >
- >I haven't seen the origins of this thread, so excuse me if it's not
- >relevant.
- >
- >I found a way to calculate primes fairly quickly (well, I was using ARM
- >code then but the algorithm may be worth something).
- >
- >It works more on patterns within the Sieve of Erastothanes (sp?) rather than
- >the numbers themselves. Whilst working it out by hand on paper, I got
- >to the stage where I decided that 1, 2, 3 and all multiples of 2 could be
- >discarded. I then saw that beyond this, all primes numbers were a subset
- >of 6n+1 and 6n-1. So I crated a new list of numbers going 5, 7, 11, 13...
- >From these numbers, I marked the prime ones. A pattern emerged. I don't
- >know what it was, since it was a long time ago, but there is something
- >there! Anyhow, the method I used to do the calculation was to create a
- >data block in memory which was a series of 0s (I used bytes but use
- >whatever!) and then stepped through the block using the pattern to mark
- >255s (or whatever) where I had manually circled numbers on my piece of
- >paper.
- >
- >The trick was that whilst the data block was consecutive, the first
- >item represented 5, the second 7, the third 11 and so on.
- >This was not needed at execution time since only the algortihm was
- >being timed. After it had run its course, the data was gone through
- >again doing nothing more than checking for 0 "I am not prime" or
- >255 "I am prime".
- >
- >Any comments or am I way off here? ;-)
-
- I have something like this. I have a 16 megabyte bit list, where
- all of the prime bits are 0 and the non-prime bits are 1.
- I also stored only the odd bits, since even bits are not prime,
- except for 2. Hence, I can tell immediately if a number between
- 1 and 32,000,000*8 = 256,000,000 is prime. This method is not
- useful for numbers bigger than 256 million. In comp.sci.math
- there is a discussion of a new method for finding prime numbers that
- I have invented for those who are interested in that sort of thing.
- --
- The opinions expressed in this message are my own personal views
- and do not reflect the official views of Microsoft Corporation.
-
-